package cn.cjxy.controller;

import cn.cjxy.domain.User;
import cn.cjxy.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserMapper userMapper;

    @RequestMapping("findAll")
    public List<User> findAll() {
        return userMapper.findAll();
        /**
         * [
         *   {
         *     "id": 1,
         *     "username": "张三",
         *     "birthday": "1999-02-03T16:00:00.000+00:00",
         *     "sex": "男",
         *     "address": "佛山"
         *   },
         *   {
         *     "id": 2,
         *     "username": "李四",
         *     "birthday": "1998-01-14T16:00:00.000+00:00",
         *     "sex": "女",
         *     "address": "湛江"
         *   }
         * ]
         */
    }

    @GetMapping("/{id}")
    public User findById(@PathVariable Integer id) {
        return userMapper.findById(id);
    }

    @PostMapping("/save")
    public void save(@RequestBody User user) {
        userMapper.insert(user);
    }
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id) {
        userMapper.delete(id);
    }
}
